//
//  RegardViewController.m
//  HTHappySale
//
//  Created by 创维海通 on 2017/9/26.
//  Copyright © 2017年 zxyywy. All rights reserved.
//

#import "RegardViewController.h"

//Tools
#import "UIImageView+WebCache.h"
#import "AppUtil.h"

//Request
#import "HTTPPromise+Me.h"

@interface RegardViewController ()
{
    NSString *ImgStr;
}
@property (strong, nonatomic) IBOutlet UIImageView *regardImg;

@end

@implementation RegardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self addNavigationLeftView:@"" andType:0];
    [self addNavigationMiddleView:@"关于"];
    
    [self initRequest];
}

- (void)initRequest{
    
    NSDictionary *aboutParam = @{};
    NSData *jsonData;
    
    if ([NSJSONSerialization isValidJSONObject:aboutParam])
    {
        NSError *error;
        jsonData = [NSJSONSerialization dataWithJSONObject:aboutParam options:NSJSONWritingPrettyPrinted error:&error];
        NSString *json =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        NSLog(@"json data:%@",json);
    }
    
    __weak __typeof(self)weakSelf = self;
    [HTTPPromise  requestAboutParams:jsonData Success:^(id responseObj) {
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        NSLog(@"%@",responseObj);
        
        int successRet =[responseObj[@"ret"] intValue];
        //(数据转模型）
        if (successRet == 0) {
            [strongSelf assembleImgUrl:responseObj[@"image"]];
        }else{
            [AppUtil showTipMessage:responseObj[@"desc"]];
        }
    } failure:^(NSError *error) {
        NSLog(@"%@",error.userInfo);
    }];
}

- (void)assembleImgUrl:(NSString *)picUrl{
    ImgStr = [NSString stringWithFormat:@"%@%@",Img_URL,picUrl];
    NSLog(@"%@",ImgStr);
    [_regardImg sd_setImageWithURL:[NSURL URLWithString:ImgStr] placeholderImage:[UIImage imageNamed:@""]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
